<template>
	<view class="logout-container">
		<!-- 标题 -->
		<view class="logout-title">
			<text>账号注销</text>
			<text style="font-size: 24rpx;font-weight: normal;color: #999;margin-top: 20rpx;">注意，注销账号后以下信息将被清空且无法找回</text>
		</view>
		
		<!-- 注销说明 -->
		<view class="logout-content">
			<view class="content-item">
				<text class="item-title">注销后，您将无法：</text>
				<view class="item-list">
					<text class="list-item">• 使用该账号登录</text>
					<text class="list-item">• 访问您的个人信息</text>
					<text class="list-item">• 查看您的订单历史</text>
					<text class="list-item">• 使用已购买的服务</text>
				</view>
			</view>
			
			<view class="content-item">
				<text class="item-title">注销前，请确保：</text>
				<view class="item-list">
					<text class="list-item">• 已备份重要信息</text>
					<text class="list-item">• 已处理完所有订单</text>
					<text class="list-item">• 已转移账户余额</text>
				</view>
			</view>
			
			<view class="content-item">
				<text class="item-title">注销是不可逆操作，请谨慎考虑。</text>
			</view>
		</view>
		
		<!-- 按钮区域 -->
		<view class="logout-buttons">
			<!-- 注销按钮 -->
			<button class="logout-btn" @click="handleLogout">
				注销
			</button>
		</view>
	</view>
</template>

<script>
import { mapActions,mapGetters } from 'vuex'

export default {
	data() {
		return {
			userData:{}
		};
	},
	computed: {
		...mapGetters(['userInfo', 'authType'])
	},
	onLoad() {
		this.userData = JSON.parse(JSON.stringify(this.userInfo));
	},
	methods: {
		...mapActions(['logout']),
		
		// 注销账户
		handleLogout() {
			uni.showModal({
				title: '确认注销',
				content: '注销后您的账户将被永久删除，无法恢复。确定要注销吗？',
				confirmText: '确认注销',
				cancelText: '取消',
				confirmColor: '#ff4444',
				success: (res) => {
					if (res.confirm) {
						this.performLogout();
					}
				}
			});
		},
		
		// 退出登录
		handleLogoutLogin() {
			uni.showModal({
				title: '确认退出',
				content: '确定要退出登录吗？',
				confirmText: '确定',
				cancelText: '取消',
				success: (res) => {
					if (res.confirm) {
						this.performLogout();
					}
				}
			});
		},
		
		// 执行退出操作
		performLogout() {
			uni.showLoading({
				title: '处理中...'
			});
			
			// 调用store中的logout方法
			this.logout();
			
			setTimeout(() => {
				uni.hideLoading();
				
				// 清除本地存储
				uni.clearStorageSync();
				
				// 强制退出应用
				// #ifdef APP-PLUS
				plus.runtime.quit();
				// #endif
				
				// #ifdef H5
				// H5环境下跳转到首页
				uni.reLaunch({
					url: '/pages/index/index'
				});
				// #endif
				
				// #ifdef MP
				// 小程序环境下跳转到首页
				uni.reLaunch({
					url: '/pages/index/index'
				});
				// #endif
				
				uni.showToast({
					title: '已注销账号',
					icon: 'success'
				});
			}, 1000);
		}
	}
}
</script>

<style lang="scss" scoped>
.logout-container {
	min-height: 100vh;
	background-color: #f8f8f8;
	padding: 20rpx;
}

.logout-title {
	text-align: center;
	padding: 40rpx 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	text {
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
	}
}

.logout-content {
	background-color: #fff;
	border-radius: 16rpx;
	padding: 30rpx;
	margin-bottom: 40rpx;
	
	.content-item {
		margin-bottom: 30rpx;
		
		&:last-child {
			margin-bottom: 0;
		}
		
		.item-title {
			font-size: 28rpx;
			font-weight: bold;
			color: #333;
			display: block;
			margin-bottom: 16rpx;
		}
		
		.item-list {
			.list-item {
				font-size: 26rpx;
				color: #666;
				line-height: 1.6;
				display: block;
				margin-bottom: 8rpx;
			}
		}
	}
}

.logout-buttons {
	padding: 0 20rpx;
	
	.logout-btn {
		width: 100%;
		height: 88rpx;
		background: linear-gradient(135deg, #ff4444, #ff6666);
		color: #fff;
		border: none;
		border-radius: 44rpx;
		font-size: 32rpx;
		font-weight: bold;
		margin-bottom: 20rpx;
		
		&:active {
			opacity: 0.8;
		}
	}
	
	.logout-login-btn {
		width: 100%;
		height: 88rpx;
		background: #fff;
		color: #666;
		border: 2rpx solid #ddd;
		border-radius: 44rpx;
		font-size: 32rpx;
		
		&:active {
			background-color: #f5f5f5;
		}
	}
}
</style>
